Part Number Hot Search : 
4D471K 67YR1M STB13007 2SK33 AD5100 GPTK2126 CT244 2SD1658
Product Description
Full Text Search
 

To Download AN4112 Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  june 2012 doc id 023195 rev 1 1/17 AN4112 application note using stm32f05xx analog compar ators in application cases introduction this document describes six application cases of the two analog comparators embedded in the ultra-low power stm32f05xx product line. the application cases are: analog voltage monitoring analog watchdog during stop mode pulse width measurement pulse width modulation (pwm) signal control capacitance measurement brightness control using a light dependent resistor (ldr) the six application cases demonstrate the usefulness of analog comparators and show how they are integrated with other peripherals, for example, the digital-to-analog-converter (dac) and timers. to ensure a quick start, four application cases presented in this document are implemented in c language and available in project\stm32f0xx_stdperiph_examples\comp within the stm32f0xx_stdperiph_lib package. please note that this document is not intended to replace the comparator section in the product reference manual rm0091 (for stm32f05xx ). the peripheral power consumption should be consulted in the device datasheets. table 1. applicable products type part numbers microcontrollers stm32f05xx www.st.com
contents AN4112 2/17 doc id 023195 rev 1 contents 1 analog voltage monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 2 analog watchdog during st op mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 3 pulse width measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 4 pwm signal control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 5 capacitance measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 6 brightness control usin g a light d ependent resistor (ldr) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14 7 revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
AN4112 list of figures doc id 023195 rev 1 3/17 list of figures figure 1. sensor output connection to comp2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 figure 2. power consumption in an analog voltage monitoring application . . . . . . . . . . . . . . . . . . . . . 5 figure 3. comp2 configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6 figure 4. analog comparators combined in window mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 figure 5. analog watchdog during stop mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8 figure 6. comp2 with output redirection feature. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9 figure 7. pulse width measurement: comp2 output redirection to timer . . . . . . . . . . . . . . . . . . . . . 10 figure 8. pwm signal control: comp2 output redirection to timer . . . . . . . . . . . . . . . . . . . . . . . . . . 11 figure 9. rc network connection for capacitance measurement . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 figure 10. capacitance measurement using comp2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 figure 11. connecting an ldr resistor to an stm32f05xx device . . . . . . . . . . . . . . . . . . . . . . . . . . 14 figure 12. comparator output behavior versus light intensity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15
analog voltage monitoring AN4112 4/17 doc id 023195 rev 1 1 analog voltage monitoring the stm32f05xx devices embed a 12-bit analog-to-digital converter (adc) which is very fast with a sampling rate of 1 msample/s. however, with a 1.5 ma typical consumption, it can jeopardize battery life time if left powered-on continuously. it is therefore recommended to use analog comparators in application cases where the analog input voltage (sensor output) needs to be measured as soon as a pre-defined threshold is exceeded. in the stm32f05xx devices, analog comparators are useful for monitoring the analog input voltage and powering-on the adc when required. while monitoring the analog voltage, the device can enter stop mode at the same time that both comparator s are still powered on. consequently, better consumption is achieved and power is saved. note: analog comparators are powered by the internal reference voltage, v refint , which is still powered-on in stop mode. once v refint is disabled, the comparators can no longer be used. in an analog voltage monitoring application, where the sensor output voltage is lower than the threshold, the mcu remains in stop mode, thereby saving power. as soon as the sensor output exceeds the threshold, the mcu is woken up, the adc is powered on and the analog input voltage is measured. when the sensor output is under the threshold, the mcu re- enters stop mode. the average power consumption is dramatically reduced when compared with an application that continuously measures the analog voltage whatever the input value. figure 1 shows how to connect a sensor output (temperature sensor, pressure sensor, pyroelectric infrared detector, photodiode sensor) to an stm32f05xx device in an analog voltage monitoring application using comparat or 2 (comp2). comp2 monitors the analog voltage in stop mode while the adc measures it in run mode. figure 1. sensor output connection to comp2 1. adc_ch1: ac channel 1 comp2_inp: comparator 2 non-inverting input 2. only if required. 34-&xx 3ensor !mplifier  &ilter  !nalog voltage !$#?#(  #/-0?).0  -36
AN4112 analog voltage monitoring doc id 023195 rev 1 5/17 figure 2. power consumption in an analog voltage monitoring application the input analog voltage can be connected to pa1 for comp1 or pa3 for comp2. the analog threshold can be provided internally through v refint and its submultiples or via an external pin through pa0 or pa5 for comp1 or pa2 or pa5 for comp2. dac channel 1 (dac_out) cannot be used in such application cases since the dac channel is powered off in stop mode. compx wakes up the device from stop mode through external interrupt lines (exti lines 21 and 22). figure 3 shows the available configurations for inverting and non-inverting inputs. 3 2 3 2 3 2 3 )nputanalogvoltage !nalogthreshold 4ime -#5state 4ime 4ime -#5currentconsumption &ewm! &ew?! ai 334/0mode 225.mode
analog voltage monitoring AN4112 6/17 doc id 023195 rev 1 figure 3. comp2 configuration 1. dac_out: dac channel 1 output v refint : internal reference voltage comp2out: comparator 2 ou tput (internal output) when the device enters stop mode, only comp2 and the internal reference voltage, v refint , remain powered on. note: refer to the device datasheet for power consumption values. -36 0!  0!  )nputvoltage #/-0 7akeup %84)line #/-0/54 !nalogthreshold multiplesources 0!  6 2%&).4 6 2%&).4 6 2%&).4 6 2%&).4 $!#?/54
AN4112 analog watchdog during stop mode doc id 023195 rev 1 7/17 2 analog watchdog during stop mode the adc in the stm32f05xx family can be used as an analog watchdog with programmable high and low thresholds. nevertheless, the mcu must be kept in run mode to be able to watch the analog voltage on the input since the adc is powered off in stop mode. for stm32f05xx devices, two analog comparators, comp1 and comp2, can be combined in window mode and used as an analog watchdog that remains powered on while the mcu is stopped. consequently, lower consumption is achieved and power is saved. figure 4 displays the configuration of two such analog comparators in window mode. threshold1 is set to the internal reference voltage, v refint , and threshold2 is configurable among v refint , 3/4 v refint , 1/2 v refint , 3/4 v refint , dac_out, or the external pin (pa2 or pa5). the analog input voltage can be applied on (pa1 or pa3) pin. figure 4. analog comparators combined in window mode note: dac_out1 cannot be used in stop mode since the dac peripheral is powered off. in an analog watchdog application, comp1 is configured through external interrupt line 21 (exti line 21) to exit the mcu from stop mode when the analog input voltage exceeds v refint . comp2 is set, through exti line 22, to exit the mcu from stop mode when the analog voltage goes below the lower threshold. throughout the time the analog voltage is within the defined thresholds, the mcu is in stop mode and power consumption is reduced. when the analog voltage exceeds the defined thresholds, the average power consumption can be reduced by switching to run mode. figure 5 gives an overview of an analog watchdog application with threshold1 higher than threshold2. -36 0!  0!  )nputvoltage #/-0 7akeup %84)line #/-0/54 !nalogthreshold multiplesources 0!  6 2%&).4 6 2%&).4 6 2%&).4 6 2%&).4 0!  $!#?/54
analog watchdog during stop mode AN4112 8/17 doc id 023195 rev 1 figure 5. analog watchdog during stop mode 1. while the mcu is in stop mode, the input vo ltage exceeds threshold1 and the mcu exits stop mode. 2. while the mcu is in run mode, the input volt age goes below threshold1 and the mcu enters stop mode. 3. while the mcu is in stop mode, the input voltage goes below threshold2 and the mcu exits stop mode. note: in stop mode, only comp1, comp2 and v refint continue to consume power. refer to the specific device datasheet for power consumption values. -#5state 4ime 4hreshold v 2%&).4 -#5exits 34/0mode 4hreshold 3ensoroutput voltage -#5enters 34/0mode -#5exits34/0mode 6 4ime -36
AN4112 pulse width measurement doc id 023195 rev 1 9/17 3 pulse width measurement in stm32f05xx devices, the comp2 output can be redirected to the bkin (break input) of the embedded timer tim1. redirecting the comp2 output allows a signal width or frequency with specific low and high levels (for example, a shifted signal) to be measured. figure 6 displays all the possible output redirections of the comp2 output. the input signal, whose signal width should be measured, is connected to (pa3 or pa1). the reference signal can be powered by: an internal reference (v refint , 3/4 v refint , 1/2 v refint , or 1/4 v refint ) the built-in dac (channel 1) an external pin through pa2 the comp2 output redirection is achieved through the comp2outsel[2:0] bits. the timer input capture channel is configured to save the timer counter at both rising and falling edges. when the i nput signal goes above the refer ence voltage, the comp2 output is at a high level, generating a rising edge on the timer input capture. when the input signal goes under the refe rence voltage, the comp2 output is at low level, generating a falling edge. the elapsed time between the two consecutive events (falling then rising edge or rising then falling ed ge) represents t he pulse width. hence, the pulse width measurement is performed by simple subtraction of the counter values. figure 7 gives an overview of the pulse width measurement as measured by comp2. figure 6. comp2 with output redirection feature 1. dac_out: dac channel 1 output v refint : internal reference voltage comp2out: comparator 2 output (internal output) tim1_bk1: timer 1 break input timx icy: timer x input capture channel y timx _ocref_clr: timer x out put compare reference clear 0!  4hreshold multiplesources - + #/-0 0!  #/-0/54 7akeup %84)line 0!  $!#?/54 0!  62%&).4 62%&).4 62%&).4 62%&).4 )nputvoltage 4)-?"+). 4)-?/#ref?clr 4)-?)# 4)-?)# 4)-?/#ref?clr 4)-?)# 4)-?/#ref?clr #/-0/543%,;= -36
pulse width measurement AN4112 10/17 doc id 023195 rev 1 figure 7. pulse width measurement: comp2 output redirection to timer 1. the duration that should be measured. note: 1 the signal frequency can be achieved by configuring the timer input capture channel to save the counter value on only a rising or falling edge. 2 the dac outputs (dac_out) can be used as inverting inputs to allow the reference voltage level (threshold) to be internally provided and programmable by software from 0 v to v ref+ . 2eferencevoltage duration  stcapture ,owlevel #/-0output highlevel )nputsignal 4ime 4ime 4ime  4imercounter  duration  ndcapture stcapture ndcapture stcapture ai
AN4112 pwm signal control doc id 023195 rev 1 11/17 4 pwm signal control in stm32f05xx devices, the comp2 output can be redirected to the bkin input(break input)of the embedded timer tim1(refer to figure 6: comp2 with output redirection feature ). the possibility of redirecting the comp2 output can be used to provide a fast response time that is independent from the system frequency when an analog event occurs. this application case controls a pwm signal for motor control when the current sensor output is connected to the comp2 non-inverting input. in this situation, the reference voltage is connected to the comp2 inverting input. when the current sensor output exceeds the selected threshold, the comp2 output goes high and the pwm signals switch to safe state. figure 8. pwm signal control: comp2 output redirection to timer note: when the current sensor voltage reaches the reference voltage, the comp2 output goes high. consequently, the pwm and output compare reference signals go low (to safe state). 4ime 07-signal 4ime 07-signalatsafestatelowlevel 4ime #/-0outputisathighlevel ,owlevel (ighlevel #/-0output #urrentsensoroutput 2eferencevoltage ai
capacitance measurement AN4112 12/17 doc id 023195 rev 1 5 capacitance measurement the ability to connect the comp2 output to the input capture channels of the timers allows the capacitance value to be measured. the prin ciple is based on measuring the charge time of a resistor-capacitor (rc) network as follows: the charge time is measured the charge resistor (r) is already known the unknown capacitance (c) can be computed figure 9 shows the hardware connection of the rc network to an stm32f05xx device. figure 9. rc network connection for capacitance measurement the capacitance measurement procedure cons ists of charging and discharging the capacitor through the resistor. the charge/discharge function follows an exponential curve. the charge function is given by example 1 . example 1 where: v dd is the positive supply voltage t is the time t is the rc constant charging and discharging the rc network is ensured by the timer output compare channel (timx oc) configured in pwm mode. the timer channel is connected to the resistor. the input voltage is connected to the comp2 non-inverting input while the threshold is connected to the comp2 inverting input. when the input voltage crosses the threshold, the comp2 output switches to high level and a capture event occurs saving the counter value. figure 10 shows the capacitance measurement. 4)-x)# #/-0 4hreshold 4)-x/# )nputvoltage # 2 -36 input voltage v dd 1tt ? ? () exp ? () =
AN4112 capacitance measurement doc id 023195 rev 1 13/17 figure 10. capacitance measurement using comp2 at the moment where the input voltage crosses the threshold and the comp2 output switches to high level, the charge function is given by equation 1 . equation 1 where "tc" is the time when the input voltage crosses the threshold. using equation 1 the capacitance value can be computed by equation 2 . equation 2 usually r, the threshold, and v dd are constant, so, measuring the capacitance is reduced to solving for equation 3 . equation 3 where k is solved using equation 4 equation 4 4hreshold 4)-x/#y 4ime )nputvoltage 4ime 4ime #aptureevent  4ime #/-0 output  4imercounter #aptureevent #aptureevent ai threshold vdd 1 -tc t ? () exp ? () = c t r 1-threshold v dd () ? () ln () ? ? = ctk ? ? = k r 1-threshold vdd () ? () ln =
brightness control using a light dependent resistor (ldr) AN4112 14/17 doc id 023195 rev 1 6 brightness control using a light dependent resistor (ldr) in some battery operated applications, the microcontroller needs to be powered if the environment is lit; otherwise, it must be kept powered off. for such applications, a light dependent resistor (ldr), whose resistance depends on light intensity, is useful to control the microcontroller state. using an ldr sensor, the microcontroller can switch to/from low power mode depending on the voltage provided by the ldr resistor. figure 11 shows how to connect an ldr resistor to an stm32f05xx device. the comp2 non-inverting input can be connected to an ldr resistor through a voltage divider (v in ). the threshold can be set externally to the pa2 or pa5 pin or set internally to v refint , 3/4 v refint , 1/2 v refint , or 1/4 v refint . the comp2 output (comp2out) can be internally connected to exti line 22 which, when configured to detect both rising and falling edges on comp2out, can be used as an interrupt source to switch to/from low power mode. figure 11. connecting an ldr resistor to an stm32f05xx device 1. pa3 or pa1 can be used as comp2 non-inverting input. thus, v in can be connected to pa3 or pa1. the voltage v in can be computed using equation 5 . equation 5 as the ldr resistance decreases with in creasing light intensity, the voltage v in decreases as more light shines on the ldr. ms30286v1 v refint ?v refint ?v refint ?v refint other possibilities pa2/pa5 pa3/pa1 (1) comp2 + - exti line 22 comp2out light dependent resistor (ldr) v dd resistor (r) v in stm32f05xx v in ldr ldr r + () --------------------------- - v dd =
AN4112 brightness control using a light dependent resistor (ldr) doc id 023195 rev 1 15/17 the top part of figure 12 shows the evolution of v in as a function of light variation. the selected threshold (comp2 invert ing input) defines the limit of dark/light. the bottom part of figure 12 shows that the comp2 output (comp2out) level depends on v in and consequently on light intensit y. using exti line 22 (which is internally connected to comp2out), the microcontroller can detect the comp2out level switch (from a high level to a low level or vice versa ). figure 12. comparator output behavior versus light intensity the ldr resistor can be used in other microcontroller-based applications rather than darkness control (for example: dc relay control and autofocus). for other uses of analog comparators using ldr resistors, refer to the stm320518-eval (for stm32f05xx devices) demonstration firmware. in this demonstration, when the luminosity changes, the progress bar displayed on the color lcd changes according to light intensity level detected using the comparator. 4hreshold 4ime 4ime ,owlevel (ighlevel $ark ,ight ,ight 6 ). threshold 6 ). threshold 6 ). -icrocontrollerenters ,owpowermode -icrocontrollerexits ,owpowermode #/-0/54 %84) -36
revision history AN4112 16/17 doc id 023195 rev 1 7 revision history table 1. document revision history date revision changes 26-jun-2012 1 initial release.
AN4112 doc id 023195 rev 1 17/17 please read carefully: information in this document is provided solely in connection with st products. stmicroelectronics nv and its subsidiaries (?st ?) reserve the right to make changes, corrections, modifications or improvements, to this document, and the products and services described he rein at any time, without notice. all st products are sold pursuant to st?s terms and conditions of sale. purchasers are solely responsible for the choice, selection and use of the st products and services described herein, and st as sumes no liability whatsoever relating to the choice, selection or use of the st products and services described herein. no license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted under this document. i f any part of this document refers to any third party products or services it shall not be deemed a license grant by st for the use of such third party products or services, or any intellectual property contained therein or considered as a warranty covering the use in any manner whatsoev er of such third party products or services or any intellectual property contained therein. unless otherwise set forth in st?s terms and conditions of sale st disclaims any express or implied warranty with respect to the use and/or sale of st products including without limitation implied warranties of merchantability, fitness for a parti cular purpose (and their equivalents under the laws of any jurisdiction), or infringement of any patent, copyright or other intellectual property right. unless expressly approved in writing by two authorized st representatives, st products are not recommended, authorized or warranted for use in milita ry, air craft, space, life saving, or life sustaining applications, nor in products or systems where failure or malfunction may result in personal injury, death, or severe property or environmental damage. st products which are not specified as "automotive grade" may only be used in automotive applications at user?s own risk. resale of st products with provisions different from the statements and/or technical features set forth in this document shall immediately void any warranty granted by st for the st product or service described herein and shall not create or extend in any manner whatsoev er, any liability of st. st and the st logo are trademarks or registered trademarks of st in various countries. information in this document supersedes and replaces all information previously supplied. the st logo is a registered trademark of stmicroelectronics. all other names are the property of their respective owners. ? 2012 stmicroelectronics - all rights reserved stmicroelectronics group of companies australia - belgium - brazil - canada - china - czech republic - finland - france - germany - hong kong - india - israel - ital y - japan - malaysia - malta - morocco - philippines - singapore - spain - sweden - switzerland - united kingdom - united states of america www.st.com


▲Up To Search▲   

 
Price & Availability of AN4112

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X